#ifndef YCBASEFUNCTIONTASK_H
#define YCBASEFUNCTIONTASK_H
#include "task.h"
#include <functional>

namespace yc {

class FunctionTask : public Task
{
    Q_OBJECT

public:
    using F = std::function<void(FunctionTask* t)>;

    FunctionTask(const F& f, int id, bool auto_delete, int timeout, QObject* parent)
        : Task(id, auto_delete, timeout, parent), f_(f)
    {
    }

private:
    void startImpl() override
    {
        if (f_) {
            f_(this);
        } else {
            Q_EMIT finished();
        }
    }

    F f_;
};
} // namespace yc

#endif // YCBASEFUNCTIONTASK_H
